/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @DatumTagAdapter.java  2014-9-12 上午10:45:34 - Carson
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.entity.UserTagModel;
import com.android.tiango.baba.util.StringUtils;

public class DatumTagAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<UserTagModel> data;
	private int count = 0;

	public DatumTagAdapter(Context context, ArrayList<UserTagModel> data,int count) {
		this.context = context;
		this.data = data;
		this.count = count;
	}

	@Override
	public int getCount() {
		return count;
	}

	@Override
	public UserTagModel getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@SuppressLint("NewApi") @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_datum_tag, null);
			holder = new ViewHolder();
			holder.tv_tag = (TextView) convertView.findViewById(R.id.tv_tag);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		UserTagModel tag = getItem(position);
		String tagName = tag.getTagName();
		
		holder.tv_tag.setText(tagName);
		if(tag.getIsActivated() == 1){//激活 
			String color = tag.getTagColor();
			if(!StringUtils.isEmpty(color)){
				//设置颜色
				holder.tv_tag.setBackgroundColor(android.graphics.Color.parseColor(color)); 
			}
		}
		
		
		//int color = isClean(tag.getTagId());
		//if(color != -1 ){
		//	holder.tv_tag.setBackgroundColor(context.getResources().getColor(color));
		//}else{
			//已激活
//			if (tag.getIsActivated() == 1) {
//				System.out.println("已激活的");
//				String color2 = tag.getTagColor();
//				if(!StringUtils.isEmpty(color2)){ 
//					holder.tv_tag.setBackgroundColor(android.graphics.Color.parseColor(color2)); 
//				}
//			} 
		return convertView;
	}

	class ViewHolder {
		private TextView tv_tag;
	}
	
	public void setData(ArrayList<UserTagModel> data) {
		this.data = data;
	}
}
